﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BiSA
{
     
    class GoogleChart
    {
        public struct VennDiagram {
            public string CircleALabel;
            public string CircleALabelValue;
            public string CircleBLabel;
            public string CircleBLabelValue;
            public string CircleCLabel;
            public string CircleCLabelValue;
            public string IntersectionAB;
            public string IntersectionAC;
            public string IntersectionBC;
            public string IntersectionABC;

        }

        public static string API = "http://chart.apis.google.com/chart?";
        public string generateVenn(VennDiagram venn, string width, string height)
        {
            string param ="chs=" + width + "x" + height + "&cht=v&chds=0," + toMaxValue(venn);
            string chdl = "&chdl=" + venn.CircleALabel + "|" + venn.CircleBLabel;
            param += "&chd=t:" + venn.CircleALabelValue;
            param += "," + venn.CircleBLabelValue;
            param += "," + venn.CircleCLabelValue;
            param += "," + venn.IntersectionAB;
            if (!venn.CircleCLabelValue.Equals("0"))
            {
                param += "," + venn.IntersectionAC;
                param += "," + venn.IntersectionBC;
                param += "," + venn.IntersectionABC;
                chdl = "|" + venn.CircleCLabel;
            }
            param += chdl;
            return API + param;
        }

        private string toMaxValue(VennDiagram venn)
        {
            int a =Convert.ToInt32(venn.CircleALabelValue);
            int b =Convert.ToInt32(venn.CircleBLabelValue);
            int c=0;
            if (venn.CircleCLabelValue==null) //if there are only two circles
            {
                return Math.Max(a, b).ToString();
            }
            else
            {
                c = Convert.ToInt32(venn.CircleALabelValue);
                return Math.Max(Math.Max(a, b), c).ToString();
            }

        }
    }
}
